package com.jvyou.app.ds.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;
import com.jvyou.app.ds.domain.dto.CoachDto;
import com.jvyou.app.ds.domain.dto.FaqDto;
import com.jvyou.app.ds.domain.entity.Coach;
import com.jvyou.app.ds.domain.entity.Faq;
import com.jvyou.app.ds.service.FaqService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 驾校系统常见问题表(Faq)表控制层
 *
 * @author 橘柚
 * @since 2025-04-20 12:16:44
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/faq")
public class FaqController {

    private final FaqService faqService;

    @GetMapping("/list")
    @SaCheckPermission("ds:faq:list")
    public Result<List<Faq>> list(@ModelAttribute FaqDto faqDto) {
        return Result.success(faqService.listFaq(faqDto));
    }

    @GetMapping("/page")
    @SaCheckPermission("ds:faq:page")
    public Result<PageResult<Faq>> page(@ModelAttribute FaqDto faqDto) {
        return Result.success(faqService.pageFaq(faqDto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("ds:faq:get")
    public Result<Faq> selectOne(@PathVariable Long id) {
        return Result.success(faqService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param faq 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("ds:faq:insert")
    public Result<Faq> insert(@RequestBody Faq faq) {
        boolean success = faqService.save(faq);
        return success ? Result.success(faq) : Result.error(HttpCodeEnum.ADD_FAIL);
    }

    /**
     * 修改数据
     *
     * @param faq 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("ds:faq:update")
    public Result<Boolean> updateById(@RequestBody Faq faq) {
        boolean success = faqService.updateById(faq);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }


    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("ds:faq:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = faqService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }

}

